/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DiscussionPanel.java
 *
 * Created on Oct 21, 2011, 9:19:04 PM
 */
package teletutor.classroommanager.UI;

import teletutor.classroommanager.services.ClassroomManager;
import teletutor.classroommanager.services.TextMessage;
import teletutor.classroommanager.services.TextMessageObserver;

/**
 *
 * @author Rae
 */
public class DiscussionPanel extends javax.swing.JPanel implements TextMessageObserver {
    ClassroomManager crman;
    /** Creates new form DiscussionPanel */
    public DiscussionPanel(ClassroomManager crman) {
        initComponents();
        
        this.crman = crman;
        crman.addTMObserver(this);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        discussionLineEdit = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        discussionText = new javax.swing.JTextArea();

        discussionLineEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                discussionLineEditActionPerformed(evt);
            }
        });

        discussionText.setColumns(20);
        discussionText.setRows(5);
        jScrollPane1.setViewportView(discussionText);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addComponent(discussionLineEdit, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 252, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(discussionLineEdit, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void discussionLineEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_discussionLineEditActionPerformed
       crman.sendTextMessage(discussionLineEdit.getText());
       discussionLineEdit.setText("");
    }//GEN-LAST:event_discussionLineEditActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField discussionLineEdit;
    private javax.swing.JTextArea discussionText;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

    @Override
    public void newTextMessage(TextMessage message) {
        discussionText.append(message.toString());
    }
}
